﻿using System.Linq;
using Extension.Runtime;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

namespace UIModule.Editor
{
    public class CustomUICreator
    {
        [MenuItem("GameObject/UI/CreateWindow")]
        public static void CreateWindow()
        {
            Transform root = GameObject.FindObjectsOfType<Canvas>().First(t => t.name == "UIRoot").transform;
            GameObject go = new GameObject("Window", typeof(Canvas), typeof(GraphicRaycaster), typeof(DataInjection));
            go.layer = LayerMask.NameToLayer("UI");
            Canvas canvas = go.GetComponent<Canvas>();
            go.transform.SetParent(root);
            GraphicRaycaster raycaster = go.GetComponent<GraphicRaycaster>();
            DataInjection dataInjection = go.GetComponent<DataInjection>();
            canvas.overrideSorting = true;
            go.GetComponent<RectTransform>().SetRectFullScreen();
            go.transform.Reset();
        }
    }
}